import 'package:flutter/material.dart';
import 'package:flutter_sample/tab/ui/home/article/category_articles_ui.dart';
import 'package:flutter_sample/tab/ui/home/mine/ui_mine.dart';

class UITabHome extends StatefulWidget {

  UITabHome({Key? key}) : super(key: key);

  final List<Widget> bodyPages = [
    const CategoryArticlesUI(),
    const MinePage(),
  ];

  final List<BottomNavigationBarItem> bottomTabs = [
    const BottomNavigationBarItem(
      icon: Icon(Icons.home_rounded),
      label: "首页",
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.adb),
      label: "我的",
    ),
  ];

  @override
  State<StatefulWidget> createState() => _HomePage();
}

class _HomePage extends State<UITabHome> {
  int _index = 0;

  void onBottomTabChange(int index) {
    setState(() {
      _index = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: true,
        child: IndexedStack(
          index: _index,
          children: widget.bodyPages,
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        selectedFontSize: 12,
        unselectedFontSize: 12,
        items: widget.bottomTabs,
        onTap: onBottomTabChange,
        currentIndex: _index,
      ),
    );
  }
}
